home *** CD-ROM | disk | FTP | other *** search
/ Amiga Format CD 52 / Amiga Format AFCD52 (Issue 136, May 2000).iso / -serious- / programming / c / roboticsdp / examples / highratescan / source / highratescan.c < prev   
Encoding:
C/C++ Source or Header  |  2000-02-28  |  2.5 KB  |  82 lines

  1. /*****************************************************************************/
  2. /* INCLUDES INCLUDES INCLUDES INCLUDES INCLUDES INCLUDES INCLUDES INCLUDES I */
  3. /*****************************************************************************/
  4. #include <clib/exec_protos.h> /* OpenLibrary & CloseLibrary */
  5. #include <stdio.h>            /* For printing error messages */
  6. #include <minissc.h>          /* minissc library definitions */
  7.  
  8. /*****************************************************************************/
  9. /* VARIABLES VARIABLES VARIABLES VARIABLES VARIABLES VARIABLES VARIABLES VAR */
  10. /*****************************************************************************/
  11. struct MiniSSCLibrary *MiniSSCBase=NULL; /* Library base */
  12.  
  13. /*****************************************************************************/
  14. /* MAIN MAIN MAIN MAIN MAIN MAIN MAIN MAIN MAIN MAIN MAIN MAIN MAIN MAIN MAI */
  15. /*****************************************************************************/
  16. void main(void)
  17. {
  18.     /* Variables */
  19.     int controller=0;  /* Use controller number 0*/
  20.     int servo=0;       /* Use servo number 0 */
  21.     int position;      /* Servo position looper */
  22.     int step=1;        /* Speed of movement */
  23.     int servorange=90; /* Servo's motion range in degrees */
  24.  
  25.     /* Open minissc library */
  26.     if(MiniSSCBase=(struct MiniSSCLibrary *)OpenLibrary(SSC_NAME,SSC_VERSION))
  27.     {
  28.         /* Occupy controller */
  29.         if(!ssc_OccupyController(controller,SSC_COMMMODE_HIGH,SSC_CTRLMODE_NARROW))
  30.         {
  31.             /* Occupy servo */
  32.             if(!ssc_OccupyServo(servo,servorange))
  33.             {
  34.                 /* Rotate servo in clockwise */
  35.                 for(position=0;position<=SSC_MAX_AVALUE;position=position+step)
  36.                 {
  37.                     ssc_SetAPosition(servo,position);
  38.                 }
  39.                 /* Rotate servo in anticlockwise */
  40.                 for(position=SSC_MAX_AVALUE-1;position>=0;position=position-step)
  41.                 {
  42.                     ssc_SetAPosition(servo,position);
  43.                 }
  44.  
  45.                 /* Free servo */
  46.                 ssc_FreeServo(servo);
  47.  
  48.                 /* Free controller */
  49.                 ssc_FreeController(controller);
  50.  
  51.                 /* Close library */
  52.                 CloseLibrary((struct Library *)MiniSSCBase);
  53.             }
  54.             /* Servo is not available */
  55.             else
  56.             {
  57.                 /* Free controller */
  58.                 ssc_FreeController(controller);
  59.  
  60.                 /* Close library */
  61.                 CloseLibrary((struct Library *)MiniSSCBase);
  62.  
  63.                 /* Print error message */
  64.                 printf("can't occupy servo #%d\n",servo);
  65.             }
  66.         }
  67.         /* Controller is not available */
  68.         else
  69.         {
  70.             /* Close library */
  71.             CloseLibrary((struct Library *)MiniSSCBase);
  72.  
  73.             /* Print error message */
  74.             printf("can't occupy controller #%d\n",controller);
  75.         }
  76.     }
  77.     /* minissc.library not available */
  78.     else
  79.     {
  80.         printf("can't open %s\n",SSC_NAME);
  81.     }
  82. }